import Vue from 'vue'
import * as Util from '../components/Util'

let LogicService = {
  install (Vue, options) {
    // 给vue增添对话框显示方法
    Vue.LogicService = Vue.prototype.$LogicService = LogicService
  },

  // 阀控
  valveControl (model, row) {
    let data = {
      userfile: {
        f_user_id: row.f_user_id,
        f_valve_state: model.valvaStatus,
        version: row.version
      },
      record_userinfo: row.f_userinfo_id,
      f_user_id: row.f_user_id,
      f_userinfo_id: row.f_userinfo_id,
      f_user_name: row.f_user_name,
      f_enable_state: '有效',
      f_reason: model.f_reason,
      f_operat_type: '启用',
      f_describe: '对用户' + row.f_user_name + '进行' + model.valvaStatus + '操作',
      f_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname
    }
    return Vue.resetpost('rs/entity/t_enable', data, {resolveMsg: '阀控成功', rejectMsg: '阀控失败'})
  },

  // 表具启用
  meterEnable (model, row) {
    let data = {
      userfile: {
        f_user_id: row.f_user_id,
        f_table_state: '正常',
        version: row.version
      },
      record_userinfo: row.f_userinfo_id,
      f_user_id: row.f_user_id,
      f_userinfo_id: row.f_userinfo_id,
      f_user_name: row.f_user_name,
      f_enable_state: '有效',
      f_reason: model.f_reason,
      f_operat_type: '启用',
      f_describe: '对用户' + row.f_user_name + '进行表具启用',
      f_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname
    }
    return Vue.resetpost('rs/entity/t_enable', data, {resolveMsg: '表具启用成功', rejectMsg: '表具启用失败'})
  },

  // 表具停用
  meterDisable (model, row) {
    let data = {
      userfile: {
        f_user_id: row.f_user_id,
        f_table_state: '停用',
        version: row.version
      },
      record_userinfo: row.f_userinfo_id,
      f_user_id: row.f_user_id,
      f_userinfo_id: row.f_userinfo_id,
      f_user_name: row.f_user_name,
      f_disable_state: '有效',
      f_reason: model.f_reason,
      f_operat_type: '停用',
      f_describe: '对用户' + row.f_user_name + '进行表具停用',
      f_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname
    }
    return Vue.resetpost('rs/entity/t_disable', data, {resolveMsg: '表具停用成功', rejectMsg: '表具停用失败'})
  },

  // 其他收费
  otherCharge (model, row) {
    let data = {
      record_userinfo: row.f_userinfo_id,
      f_user_id: row.f_user_id,
      f_number: model.f_number,
      f_unitprice: model.f_unitprice,
      f_collection: model.f_collection,
      f_note: model.f_note,
      f_charge_type: model.f_charge_type[0],
      f_brand_spec: model.f_brand_spec[0],
      f_userinfo_id: row.f_userinfo_id,
      f_operat_type: '其他收费',
      f_describe: '对用户' + row.f_user_name + '进行其他收费',
      f_state: '有效',
      f_charge_state: '有效',
      f_operator: Util.f.name,
      f_filiale: Util.f.f_fengongsi,
      f_outlets: Util.f.f_parentname
    }
    return Vue.resetpost('rs/entity/t_othercharge', data, {resolveMsg: '其他收费成功', rejectMsg: '其他收费失败'})
  },

  // 过户管理
  changeAccount (model) {
    return Vue.resetpost('rs/logic/transferSave', {data: {model: model}}, {resolveMsg: '过户成功', rejectMsg: '过户失败'})
  },

  // 批量变更抄表员
  updateInputtor (data) {
    return Vue.resetpost('rs/logic/updateBatch', data, {resolveMsg: '批量修改成功', rejectMsg: '批量抄表员变更失败'})
  },
  // 批量变更水价
  updateWaterPrice (data) {
    return Vue.resetpost('rs/logic/updateBatchPrice', data, {resolveMsg: '批量修改成功', rejectMsg: '批量变更水价失败'})
  },
  // 增加水表品牌
  addWaterBrand (model, Arrlist) {
    let data = {
      f_meter_brand: model.f_meter_brand,
      f_manufacturers: model.f_manufacturers,
      f_meter_type: model.f_meter_type,
      f_police_water: model.f_police_water ? model.f_police_water : 0,
      f_card_password: model.f_card_password,
      f_topup_ceil: model.f_topup_ceil ? model.f_topup_ceil : 0,
      f_overdr_lines: model.f_overdr_lines ? model.f_overdr_lines : 0,
      f_meter_limit: model.f_meter_limit ? model.f_meter_limit : 0,
      f_checkout_limit: model.f_checkout_limit ? model.f_checkout_limit : 0,
      f_alias: model.f_alias,
      watermodellist: Arrlist
    }
    return Vue.resetpost('rs/logic/addWaterBrand', {data: data}, {resolveMsg: '添加水表成功', rejectMsg: '增加水表失败'})
  },
  // 修改水表品牌
  modifyWaterBrand (model, Arrlist) {
    return Vue.resetpost('rs/logic/updataWaterBrand', {data: {data: model, watermodellist: Arrlist}}, {resolveMsg: '修改水表品牌成功', rejectMsg: '修改水表品牌失败'})
  },
  // 删除水表品牌
  delWaterBrand (f_id) {
    return Vue.resetpost('rs/logic/delWaterBrand', {data: {id: f_id}}, {resolveMsg: '删除成功', rejectMsg: '删除失败'})
  },
  createMessage (data) {
    return Vue.resetpost('rs/logic/messageBatchOperate', data, {resolveMsg: '生成短信成功', rejectMsg: '生成短信失败'})
  },
  waterPrice (model, row) {
    let data = {
      f_price_type: model.f_price_type[0],
      f_price_name: model.f_price_name,
      f_user_type: model.f_user_type[0],
      f_waterproperties: model.f_waterproperties[0],
      f_stairmonths: model.f_stairmonths,
      f_perform_date: model.f_perform_date,
      f_end_date: '',
      f_state: '有效',
      detailprice: model.detailprice,
      type: '添加'
    }
    if (row && row.id != null) {
      data.oldprice = {
        id: row.id,
        f_state: '无效',
        f_end_date: model.f_perform_date
      }
      data.type = '修改'
      data.f_userprice_id = row.f_userprice_id
    }
    return Vue.resetpost('rs/logic/waterprice', {data: data})
  },
  sendMessage (condition) {
    return Vue.resetpost('rs/logic/sendSms', {condition: condition})
  },
  deletMessage (condition) {
    return Vue.resetpost('rs/logic/deleteSms', {condition: condition}, {resolveMsg: '删除短信成功', rejectMsg: '删除短信失败'})
  },
  discountsPrice (model, row) {
    let data = {
      f_discounts_type: model.f_discounts_type[0],
      f_waterproperties: model.f_waterproperties[0],
      f_discount_water: model.f_discount_water,
      f_discount_proport: model.f_discount_proport / 100,
      f_remark: model.f_remark,
      f_state: '有效',
      f_operator: Util.f.name,
      type: '新增'
    }
    if (row && row.id != null) {
      data.oldprice = {
        id: row.id,
        f_state: '无效'
      }
      data.type = '修改'
      data.f_userdiscounts_id = row.f_userdiscounts_id
    }
    return Vue.resetpost('rs/logic/discountsPrice', {data: data})
  },
  addSplit (row, condition) {
    let data = {
      total: {},
      condition: condition
    }
    data.total.f_user_id = row.f_user_id
    return Vue.resetpost('rs/logic/addSplit', {data: data})
  }
}

export default LogicService
